﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using TelerikedIn.Models;
using TelerikedIn.WebApp.ViewModels.Skills;

namespace TelerikedIn.WebApp.ViewModels.Connections
{
    public class ConnectionsVM
    {
        private byte[] image;

        public ConnectionsVM()
        {
            this.ImageBytes = new byte[0];
        }

        public string UserId { get; set; }

        public string FullName { get; set; }

        public byte[] ImageBytes
        {
            get
            {
                return this.image;
            }
            set
            {
                this.image = value;
            }
        }

        public string Image 
        {
            get
            {
                return this.ImageBytes != null ? Convert.ToBase64String(this.ImageBytes) : null;
            }
        }

        public IEnumerable<SkillToEndorseVM> Skills { get; set; }

        public static Expression<Func<ApplicationUser, ConnectionsVM>> FromUser
        {
            get
            {
                return user => new ConnectionsVM
                {
                    UserId = user.Id,
                    FullName = user.FirstName + " " + user.LastName,
                    ImageBytes = user.Image,
                    Skills = user.Skills.AsQueryable().Select(SkillToEndorseVM.FromSkillEntity)
                };
            }
        }
    }
}